import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:power_house/pages/not_found.dart';
import 'package:power_house/pages/home/index.dart';
import 'package:power_house/pages/login.dart';
import 'package:power_house/pages/register.dart';
import 'package:power_house/pages/room_add/index.dart';
import 'package:power_house/pages/room_manager/index.dart';
import 'package:power_house/pages/settings.dart';
import 'package:power_house/room_detail/room_detail.dart';

class Routes {
  //1.定义路由名称
  static String home = '/index';
  static String login = '/login';
  static String register = '/register';
  static String roomDetail = '/roomDetail/:roomId';
  static String settingDetail = '/setting';
  static String roomManagerDetail = '/room_manage';
  static String roomAddDetail = '/roomAdd';

  //2.定义路由处理函数
  static final _homeHandler = Handler(handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
    return const HomePage();
  });

  //登录页面
  static final Handler _loginHandler = Handler(handlerFunc: (BuildContext context, Map<String, dynamic> params) {
    return const LoginPage();
  });

  //注册页面
  static final Handler _registerHandler = Handler(handlerFunc: (BuildContext context, Map<String, dynamic> params) {
    return const RegisterPage();
  });

  //404页面
  static final Handler _errorHandler = Handler(handlerFunc: (BuildContext context, Map<String, dynamic> params) {
    return const NoteFoundPage();
  });

  //房间详情页页面
  static final Handler _roomDetailHandler = Handler(handlerFunc: (BuildContext context, Map<String, dynamic> params) {
    return RoomDetailPage(roomId: params["roomId"]![0]);
  });

  //房间详情页页面
  static final Handler _settingsDetailHandler = Handler(handlerFunc: (BuildContext context, Map<String, dynamic> params) {
    return const SettingPage();
  });

  //房屋管理页面
  static final Handler _roomManagerHandler = Handler(handlerFunc: (BuildContext context, Map<String, dynamic> params) {
    return const RoomManagerPage();
  });

//房屋添加页面
  static final Handler _roomAddHandler = Handler(handlerFunc: (BuildContext context, Map<String, dynamic> params) {
    return const RoomAddPage();
  });

//3.编写configRoutes关联路由名称和处理函数
  static void configureRoutes(FluroRouter router) {
    router.define(home, handler: _homeHandler);
    router.define(login, handler: _loginHandler);
    router.define(roomDetail, handler: _roomDetailHandler);
    router.define(register, handler: _registerHandler);
    router.define(settingDetail, handler: _settingsDetailHandler);
    router.define(roomManagerDetail, handler: _roomManagerHandler);
    router.define(roomAddDetail, handler: _roomAddHandler);
    router.notFoundHandler = _errorHandler;
  }
}
